using MoreMountains.NiceVibrations;
using Naptime.Dev;
using UnityEngine;
using __Naptime;

public class GameplayHaptic : MonoBehaviour, ISwichHaptic
{
	private float hapticTimer;

	private bool canPlay;

	private RewiredVibrations _rewiredVibrations;

	public void Update()
	{
		hapticTimer -= Time.deltaTime;
	}

	public void PlayHaptic(HapticType type)
	{
		if (hapticTimer > 0f || NintendoPlayerPrefs.GetInt("Haptic", 1) == 0)
		{
			return;
		}
		if ((object)_rewiredVibrations == null)
		{
			_rewiredVibrations = Object.FindObjectOfType<RewiredVibrations>();
		}
		if (_rewiredVibrations == null)
		{
			SLoger.Err("RewiredVibrations is missing");
			return;
		}
		switch (type)
		{
		case HapticType.Dig:
		{
			int num = Random.Range(1, 4);
			if (num == 1)
			{
				MMVibrationManager.Haptic(HapticTypes.Selection, defaultToRegularVibrate: false, alsoRumble: true, this);
			}
			if (num == 2)
			{
				MMVibrationManager.Haptic(HapticTypes.RigidImpact, defaultToRegularVibrate: false, alsoRumble: true, this);
			}
			if (num == 3)
			{
				MMVibrationManager.Haptic(HapticTypes.LightImpact, defaultToRegularVibrate: false, alsoRumble: true, this);
			}
			hapticTimer = 0.3f;
			break;
		}
		case HapticType.Win:
			MMVibrationManager.Haptic(HapticTypes.Success, defaultToRegularVibrate: false, alsoRumble: true, this);
			break;
		case HapticType.Button:
			MMVibrationManager.Haptic(HapticTypes.Selection, defaultToRegularVibrate: false, alsoRumble: true, this);
			break;
		case HapticType.LostFuel:
			MMVibrationManager.Haptic(HapticTypes.RigidImpact, defaultToRegularVibrate: false, alsoRumble: true, this);
			break;
		case HapticType.Small:
			MMVibrationManager.Haptic(HapticTypes.LightImpact, defaultToRegularVibrate: false, alsoRumble: true, this);
			break;
		case HapticType.Big:
			MMVibrationManager.Haptic(HapticTypes.HeavyImpact, defaultToRegularVibrate: false, alsoRumble: true, this);
			break;
		}
	}

	public void HapticOff()
	{
		canPlay = false;
	}

	public void HapticOn()
	{
		canPlay = true;
	}
}
